#define DEBUG
#include <cstdio>
#define INF 0x7fffffff
#define MAXN 10000
#define MAXM 2000
#define MAXK 10

using namespace std;

class Network {
public:
  // 0:Start, 1:End, 2~n+1:Cow, n+2~n+m+1:Friend
  int n, m=1, ind[MAXN+MAXM+2], link[2*MAXN+2*MAXM*MAXK+2*MAXM+2], to[2*MAXN+2*MAXM*MAXK+2*MAXM+2], val[2*MAXN+2*MAXM*MAXK+2*MAXM+2], gap[MAXN+MAXM+2], dis[MAXN+MAXM+2];

  void init(int n) {
    gap[0] = this->n = n;
  }

  void addSide(int a, int b, int v) {
    m++;
    to[m] = b;
    val[m] = v;
    link[m] = ind[a];
    ind[a] = m;
    m++;
    to[m] = a;
    val[m] = 0;
    link[m] = ind[b];
    ind[b] = m;
  }

  int runFlow(int o, int flow, bool &flag) {
    int left=flow, ret=0;
    if (o==1) {
      return flow;
    }
    for (int i=ind[o]; i; i=link[i]) {
      if (dis[to[i]]+1==dis[o] && val[i]) {
	int run = val[i]>left ? left : val[i];
	val[i] -= run, val[i^1] += run, left-=run;
	ret += runFlow(to[i], run, flag);
	if (left==0 || flag) {
	  break;
	}
      }
    }
    gap[dis[o]]--;
    if (!gap[dis[o]]) {
      flag = true;
    }
    gap[++dis[o]]++;
    return ret;
  }
};

int main() {
#ifdef DEBUG
  freopen("4682.in", "r", stdin);
  freopen("4682.out", "w", stdout);
#endif

  static Network net;
  static int s[MAXN+1];
  int n, m, g, ans=0;
  scanf("%d %d %d", &n, &m, &g);
  net.init(n+m+2);
  for (int i=1; i<=n; i++) {
    scanf("%d", s+i);
  }
  for (int i=1; i<=n; i++) {
    int w;
    scanf("%d", &w);
    if (s[i]) {
      net.addSide(i+1, 1, w);
    } else {
      net.addSide(0, i+1, w);
    }
  }

  for (int i=1; i<=m; i++) {
    int sex, w, k, kind;
    scanf("%d %d %d", &sex, &w, &k);
    ans += w;
    for (int j=1; j<=k; j++) {
      int cow;
      scanf("%d", &cow);
      if (sex) {
	net.addSide(cow+1, i+n+1, INF);
      } else {
	net.addSide(i+n+1, cow+1, INF);
      }
    }
    scanf("%d", &kind);
    w = kind ? w+g : w;
    if (sex) {
      net.addSide(i+n+1, 1, w);
    } else {
      net.addSide(0, i+n+1, w);
    }
  }

  bool flag=false;
  for (; !flag; ans-=net.runFlow(0, INF, flag));
  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
